#include <linux/module.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include "git_version.h"


#define DRIVER_NAME "hello_misc"


static char *version = GIT_VERSION;
module_param(version, charp, S_IRUGO);


static int hello_misc_open(struct inode *inode, struct file *file)
{
    pr_info("Device opened\n");
    return 0;
}

static int hello_misc_release(struct inode *inode, struct file *file)
{
    pr_info("Device closed\n");
    return 0;
}

static ssize_t hello_misc_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
{
    // ...
    return count;
}

static ssize_t hello_misc_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
{
    // ...
    return count;
}

static const struct file_operations hello_misc_fops = {
    .owner = THIS_MODULE,
    .open = hello_misc_open,
    .release = hello_misc_release,
    .read = hello_misc_read,
    .write = hello_misc_write,
};

static struct miscdevice hello_misc_device = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = DRIVER_NAME,
    .fops = &hello_misc_fops,
};

static int __init hello_misc_init(void)
{
    int ret;

    ret = misc_register(&hello_misc_device);
    if (ret < 0) {
        pr_err("Failed to register misc device\n");
        return ret;
    }

    pr_info("MISC device registered\n");

    return 0;
}

static void __exit hello_misc_exit(void)
{
    misc_deregister(&hello_misc_device);
    pr_info("MISC device unregistered\n");
}


module_init(hello_misc_init);
module_exit(hello_misc_exit);


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple MISC driver example");
